package com.gbits.app.finance.convert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gbits.app.finance.api.ItemFinanceConvert;
import com.gbits.app.finance.domain.BusinessCashFlowSubjectMapper;
import com.gbits.app.finance.domain.CostOrgSubjectMapper;
import com.gbits.app.finance.domain.Subject;
import com.gbits.app.finance.service.BusinessCashFlowSubjectMapperService;

public class MultiBusinessCashFlowConvert extends ItemFinanceConvert {

	private BusinessCashFlowSubjectMapperService businessCashFlowSubjectMapperService;

	public BusinessCashFlowSubjectMapperService getBusinessCashFlowSubjectMapperService() {
		return businessCashFlowSubjectMapperService;
	}

	public void setBusinessCashFlowSubjectMapperService(
			BusinessCashFlowSubjectMapperService businessCashFlowSubjectMapperService) {
		this.businessCashFlowSubjectMapperService = businessCashFlowSubjectMapperService;
	}

	@Override
	public String getUsageInfo(Map<String, Object> map) {
		return "";
	}

	@Override
	public String getSubjectDetail(Map<String, Object> map) {
		String orgCode = this.getCompanyCode(map);
		String costOrgName = this.getCostOrgName(map);
		CostOrgSubjectMapper cosm = this.getCostOrgSubjectMapperService().get(orgCode, this.getCostOrgName(map));
		
		String subjectCode = cosm.getSubjectCode();
		List<Subject> subjects = this.getSubjectService().getSubjectsDetail(subjectCode, this.getSubjectName(map), orgCode);
		Subject last = subjects.get(subjects.size() - 1);
		return last.getCode() + SUBJECT_SPLIT + last.getName();
	}

	@Override
	public String getDebitAmount(Map<String, Object> map) {
		return "";
	}

	@Override
	public String getCreditAmount(Map<String, Object> map) {
		return this.getAmount(map);
	}

	@Override
	public String doConvert(Map<String, Object> map) {
		StringBuffer sb = new StringBuffer();
		sb.append("\r\n");
		sb.append("现金流量表");
		sb.append("\r\n");
		
		Map<String, Object> data = new HashMap<String, Object>();
		data.putAll(map);
		
		List<Map<String, Object>> subjectList = super.getSubjectList(map);
		// List<Map<String, Object>> taxSubject = super.getTaxList(map);
		for (int i=0; i<subjectList.size(); i++) {
			Map<String, Object> subject = subjectList.get(i);
			data.putAll(subject);
			if (i > 0) {
				sb.append("\r\n");
			}
			sb.append("");
			sb.append((i + 1) + "." + this.getSubjectDetail(data));
			sb.append("\t");
			BusinessCashFlowSubjectMapper bcfsm = this.getBusinessCashFlowSubjectMapperService().get(this.getCompanyCode(data), this.getSubjectName(data));
			sb.append(bcfsm.getInfomation());
			sb.append("\t");
			sb.append("\t");
			sb.append(this.getCreditAmount(data));
			
			
			
		}
		
		return sb.toString();
	}

}
